package testcase.doctor;

import common.Host;
import common.TestData;

import common.ImageOperation;

import java.io.File;

import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import api.doctor.ModifyDoctorUser;

/**
 * 帮忙医APP修改医生信息ModifyDoctorUser接口测试用例
 * @author lyn
 */
public class TestModifyDoctorUser
{
	/**
	 * 帮忙医APP修改医生信息ModifyDoctorUser接口测试环境数据驱动
	 * @return 测试数据
	 * @throws Exception
	 */

	@DataProvider (name = "Test")
	public static String[][] testModifyDoctorUserDataProvider() throws Exception
	{
		Host.setup("Test");
		TestData td = new TestData("doctor/TestModifyDoctorUser.xml");
		return td.getParam();	
	}
	
	/**
	 * 帮忙医APP修改个人资料ModifyDoctorUser接口测试环境用例
	 * @param caseName - 用例名称
	 * @param UserName - 用户名称
	 * @param OldPassword - 原密码
	 * @param Password - 新密码
	 * @param UserID - 用户ID
	 * @param HeadPicture - Base64编码的头像图片
	 * @return 接口返回数据
	 * @throws Exception
	 */
	@Test (dataProvider = "Test", groups = {"Test"})
	public void testModifyDoctorUserTestCase(String caseName, String UserName, String OldPassword, String Password, String UserID, String HeadPicture) throws Exception
	{
		//获取图片Base64编码字符串
		String Base64HeadPicture;
		if (HeadPicture == null) 
		{
			Base64HeadPicture = null;
		}
		else
		{
		   String fileName = System.getProperty("user.dir")
		   + File.separator + "resources"
		   + File.separator + "image"
		   + File.separator + HeadPicture;
		   Base64HeadPicture = ImageOperation.base64Encode(fileName);
		}
		
		//调用接口并将接口返回数据转换成json格式
		String result = ModifyDoctorUser.post(UserName, OldPassword, Password, UserID, Base64HeadPicture);	
		JSONObject jsonResult;
		if (result==null || result.isEmpty())
		{
			jsonResult = null;
		}
		else
		{
			jsonResult = new JSONObject(result);
		}
		
		//设置检查点
		switch (caseName)
		{
		case "UpdateModifyDoctorUser":
			Assert.assertEquals(jsonResult.getString("Sendstatus"), "Success");	//接口返回Sendstatus字段是否为Success
			Assert.assertEquals(jsonResult.getString("imagepath").isEmpty(), false);	//接口返回imagepath字段是否为空
			break;
		case "OldPassworderror":
			Assert.assertEquals(jsonResult.getString("message"), "原密码不正确!");	//接口返回message字段是否为原密码不正确!
			break;
		case "UpdatenoHeadPicture":
			Assert.assertEquals(jsonResult.getString("Sendstatus"), "Success");	//接口返回Sendstatus字段是否为Success
			break;
		case "Updatenoname":
			Assert.assertEquals(jsonResult.getString("Sendstatus"), "Success");	//接口返回Sendstatus字段是否为Success
			break;
		case "NoUserID":
			Assert.assertEquals(jsonResult.getString("message"), "Input string was not in a correct format.");	//接口返回message字段是否为Input string was not in a correct format.
			break;
		case "NoPassword":
			Assert.assertEquals(jsonResult.getString("Sendstatus"), "Success");	//接口返回Sendstatus字段是否为Success
			break;
		case "NoOldPassword":
			Assert.assertEquals(jsonResult.getString("message"), "原密码不正确!");	//接口返回message字段是否为原密码不正确!
			break;
			}	
		}		
}
	
	


